﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;
using MayhemCore;
using SensorHOL;
using Microsoft.WindowsAPICodePack.Sensors;
using System.Windows.Media.Media3D;
using System.Threading;
using SensorMayhem.Helpers;

namespace SensorMayhem.Events
{
    [DataContract]
    [MayhemModule("Sensor: Shake", "Triggers when the computer is shaked")]
    public class Shake : EventBase
    {
        AccelerometerSensorWithShakeDetection shakeDetector;

        protected override void OnEnabling(EnablingEventArgs e)
        {
            try
            {
                shakeDetector = new AccelerometerSensorWithShakeDetection();
                shakeDetector.ShakeDetected += new EventHandler(shakeDetector_ShakeDetected);
            }
            catch (Exception)
            {

            }

        }

        void shakeDetector_ShakeDetected(object sender, EventArgs e)
        {
            Trigger();
        }

        protected override void OnDisabled(DisabledEventArgs e)
        {
            try
            {
                shakeDetector.ShakeDetected -= new EventHandler(shakeDetector_ShakeDetected);
            }
            catch (Exception)
            {

            }
        }

    }
}
